<div id="view_message">
    <h1><?php echo $messages["Conversation"]["subject"] ?></h1>
    <?php
    $conversation_id = $messages["Conversation"]["id"];
    $count = 1;
    foreach ($messages["Messages"] as $message):
        if ($count == 1) {
    ?>
            <div id="photo_profile">
                <a href="<?php echo BASE_PATH; ?>/users/view/<?php echo $message["User"]["id"] ?>" ><img src="<?php echo BASE_PATH; ?>/photos/thumbs/<?php echo $message["Photo"]["filename"] ?>" alt=""/></a>
            </div>
            <div id="sender">
                <a href="<?php echo BASE_PATH; ?>/users/view/<?php echo $message["User"]["id"] ?>" ><?php echo $message["User"]["name"]; ?></a>
            </div>
            <div id="content_msg">
        <?php echo $message["Message"]["content"]; ?>
        </div>
        <div class="clear"></div>
    <?php
            $count = 0;
        }
    endforeach;
    ?>
    <div class="clear"></div>
    <a id="loadmore" href="#" style="display: none" onclick="load_more(); return false;"><div id="loadmore-message" class="loadmore">Show old replies</div></a>
    <div id="reply_list">
    </div>
    <script type="text/javascript">
        var page = 1;

        load_view();

        function load_view() {
            page = 1;

            biji.select("#reply_list").innerHTML = '<img src="<?php echo BASE_PATH; ?>/img/loading.gif" alt="" />';

            biji.load("<?php echo BASE_PATH; ?>/messages/view_ajax/<?php echo $conversation_id ?>/" + page, function(data) {
                if (data != '') {
                    biji.select("#loadmore").style.display = 'inline';
                    biji.select("#reply_list").innerHTML = data;
                } 
            });
        }

        function load_more() {
            ++page;

            biji.select("#loadmore-message").innerHTML = '<img src="<?php echo BASE_PATH; ?>/img/loading.gif" alt="" />';
        
            biji.load("<?php echo BASE_PATH; ?>/messages/view_ajax/<?php echo $conversation_id ?>/" + page, function(data) {
                if (data == '') {
                    biji.select("#loadmore").style.display = 'none';
                } else {
                    var temp = biji.select("#reply_list").innerHTML;
                    biji.select("#loadmore").style.display = 'inline';
                    biji.select("#reply_list").innerHTML = data;
                    biji.select("#reply_list").innerHTML += temp;
                }
            
                biji.select("#loadmore-message").innerHTML = 'Show old replies';
            });
        }
    </script>
    <div class="message_reply">
        <div id="photo_profile">
            <p><a href="<?php echo BASE_PATH; ?>/users/view/<?php echo $this->session->get("user_id") ?>" ><img src="<?php echo BASE_PATH; ?>/photos/thumbs/<?php echo $photo["Photo"]["filename"] ?>" alt=""/></a></p>
        </div>
        <form onsubmit="return validate_message_comment(this)" method="post" action="<?php echo BASE_PATH; ?>/messages/add_replay/<?php echo $this->session->get("user_id") ?>/<?php echo $messages["Conversation"]["id"]; ?>">
            <fieldset>
                <input type="text" name="content_message_replay" id="content_message_replay" /><br/>
                <input type="submit" name="submit" value="Post" />
            </fieldset>
        </form>
    </div>
</div>

